package main

import (
	"webook/internal/ioc"
)

func main() {
	ioc.InitViper()
	//server := gin.Default()
	//// 针对ip进行限流
	//server.Use(ratelimit.
	//	NewBuilder(client, time.Second, 100).
	//	Build())
	//// 使用 cors 中间件解决跨域问题
	//server.Use(cors.New(cors.Config{
	//	AllowCredentials: true,                                      // 允许携带cookie
	//	AllowHeaders:     []string{"Content-Type", "authorization"}, // 请求头
	//	AllowMethods:     []string{"POST"},                          // 请求方法
	//	ExposeHeaders:    []string{"x-jwt-token"},                   // 允许前端获取的请求头信息
	//	AllowOriginFunc: func(origin string) bool {
	//		return strings.HasPrefix(origin, "http://localhost")
	//	},
	//}))
	//// 使用 sessions 中间件解决登录问题
	////store := cookie.NewStore([]byte("secret"))
	//// 使用 redis 存储sessions数据
	////store, err := redis.NewStore(
	////	16, // 最大空闲连接数
	////	"tcp",
	////	"localhost:6379",
	////	"",
	////	[]byte("kUD7HXe4bMG6sUWV8pEyQ6JxNQTZkYtu"), // authentication
	////	[]byte("juBDbFxcphcBHuXccCZBC3Ch7XuExnpz"), // encryption
	////)
	////if err != nil {
	////	panic(err)
	////}
	////server.Use(sessions.Sessions("mysessions", store))
	//server.Use(middleware.NewLoginMiddlewareBuilder().
	//	IgnorePath("/users/login").
	//	IgnorePath("/users/signup").
	//	BuildByJWT())
	//
	//// 初始化cache
	//userCache := cache2.NewUserCache(client, 5*time.Minute)
	//var userDAO = dao.NewUserDAO(db)
	//var userRepo = repository.NewUserRepository(userDAO, userCache)
	//var userService = service.NewUserService(userRepo)
	//var smsSvc = memory.NewMemoryService()
	//var codeCache = cache2.NewCodeCache(client)
	//var codeRepo = repository.NewCodeRepository(codeCache)
	//var codeSvc = service.NewSmsCodeService(codeRepo, smsSvc)
	//var userHandler = web.NewUserHandler(userService, codeSvc)
	//userHandler.RegisterRoutes(server)
	app := *InitApp()
	app.Server.Run(":8081")
	app.Cron.Start()
	stopCtx := app.Cron.Stop()
	// 等待定时任务退出
	<-stopCtx.Done()
}
